<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>取得脚本中所有日期/时间函数所使用的默认时区</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.date-date-set.html">« date_date_set</a></li>
      <li style="float: right;"><a href="function.date-default-timezone-set.html">date_default_timezone_set »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.datetime.html">Date/Time 函数</a></li>
    <li>取得脚本中所有日期/时间函数所使用的默认时区</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.date-default-timezone-get" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">date_default_timezone_get</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">date_default_timezone_get</span> &mdash; <span class="dc-title">
   取得脚本中所有日期/时间函数所使用的默认时区
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.date-default-timezone-get-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>date_default_timezone_get</strong></span>(): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   本函数按照如下顺序返回默认时区：
   <ul class="itemizedlist">
    <li class="listitem">
     <p class="para">
      读取使用 <span class="function"><a href="function.date-default-timezone-set.html" class="function">date_default_timezone_set()</a></span> 函数设置的时区（如果设置了的话）
     </p>
    </li>
    <li class="listitem">
     <p class="para">
      读取 <a href="datetime.configuration.html#ini.date.timezone" class="link">date.timezone</a> ini 选项的值（如果设置了的话）
     </p>
    </li>
   </ul>
  </p>
  <p class="para">
   如果以上选择都不成功，<span class="methodname"><strong>date_default_timezone_get()</strong></span>
   会则返回默认时区 <code class="literal">UTC</code> 。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.date-default-timezone-get-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.date-default-timezone-get-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回 <span class="type">string</span>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.date-default-timezone-get-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2070">
    <p><strong>示例 #1 获取默认时区</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />date_default_timezone_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'Europe/London'</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">date_default_timezone_get</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'date_default_timezone_set:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">date_default_timezone_get</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">'&lt;br&nbsp;/&gt;'</span><span style="color: #007700">;<br />}<br /><br />if&nbsp;(</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'date.timezone'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'date.timezone:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'date.timezone'</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
date_default_timezone_set: Europe/London
date.timezone: Europe/London
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2071">
    <p><strong>示例 #2 获取时区缩写</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />date_default_timezone_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'America/Los_Angeles'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">date_default_timezone_get</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">'&nbsp;=&gt;&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'e'</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">'&nbsp;=&gt;&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'T'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
America/Los_Angeles =&gt; America/Los_Angeles =&gt; PST
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.date-default-timezone-get-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.date-default-timezone-set.html" class="function" rel="rdfs-seeAlso">date_default_timezone_set()</a> - 设置脚本中所有日期/时间函数使用的默认时区</span></li>
    <li class="member"><a href="timezones.html" class="xref">所支持的时区列表</a></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>